import operate from '@dfeidao/atom-nodejs/db/operate';
import log from '@dfeidao/atom-nodejs/logger/log';
import doc_code from '@dfeidao/atom-nodejs/msg/doc-code';
import { systemid } from '../../atom/config';

interface Message {
	fitle: {
		equip_type_name: string
		equip_type_no: string
		equip_internal_no: string
		equip_name: string
		equip_description: string
		equipment_state: string
		fixed_assets_type: string
		fixed_assets_no: string
		former_equip_no: string
		transfer_time: string
		transfer_price: number
		transfer_date: string
		manufacturer: string
		manu_country: string
		manu_years: string
		equip_model: string
		manu_element_no: string
		series_no: string
		geom: string
	};
}

export default async function atom(msg: Message, action_id: string, session_id: string) {
	log(`Service begin`);
	// todo
	const { insert, exec } = operate(action_id, session_id, systemid);
	const { result } = await doc_code(action_id, session_id, systemid, 'BM0013876', '', 1);
	if (result.length > 0) {
		insert('equipment_facilities', {
			equip_type_name: msg.fitle.equip_type_name,
			equip_type_no: msg.fitle.equip_type_no,
			equip_internal_no: msg.fitle.equip_internal_no,
			equip_no: result,
			equip_name: msg.fitle.equip_name,
			equip_description: msg.fitle.equip_description,
			equipment_state: msg.fitle.equipment_state,
			fixed_assets_type: msg.fitle.fixed_assets_type,
			fixed_assets_no: msg.fitle.fixed_assets_no,
			Former_equip_no: msg.fitle.former_equip_no,
			transfer_time: msg.fitle.transfer_time,
			transfer_price: msg.fitle.transfer_price,
			transfer_date: msg.fitle.transfer_date,
			manufacturer: msg.fitle.manufacturer,
			manu_country: msg.fitle.manu_country,
			manu_element_no: msg.fitle.manu_element_no,
			manu_years: msg.fitle.manu_years,
			equip_model: msg.fitle.equip_model,
			series_no: msg.fitle.series_no,
			geom: msg.fitle.geom
		});
	}


	const rs = await exec();
	log(`Service end`);
	return { rs, result };
}
